modelbutton: Initial accessibility setup
authorMatthias Clasen <mclasen@redhat.com>
Wed, 21 Oct 2020 20:35:39 +0000 (16:35 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 22 Oct 2020 01:27:38 +0000 (21:27 -0400)
Set the accessible role to GTK_ACCESSIBLE_ROLE_MENU_ITEM.
This is incomplete, we need to recreate the context when
the buttons role changes, and there are other things that
need to be set.

gtk/gtkmodelbutton.c

index 93f9d011fc4cf5b1e4f5d1850da6a4f9f26b6bcb..7a7b10d76a44f91571fdaabdcd8897cc9ba3a428 100644 (file)
@@ -627,6 +627,26 @@ gtk_model_button_set_active (GtkModelButton *button,
   g_object_notify_by_pspec (G_OBJECT (button), properties[PROP_ACTIVE]);
 }
 
+static void
+update_accessible_properties (GtkModelButton *button)
+{
+  if (button->menu_name || button->popover)
+    gtk_accessible_update_property (GTK_ACCESSIBLE (button),
+                                    GTK_ACCESSIBLE_PROPERTY_HAS_POPUP, TRUE,
+                                    -1);
+  else
+    gtk_accessible_reset_property (GTK_ACCESSIBLE (button),
+                                   GTK_ACCESSIBLE_PROPERTY_HAS_POPUP);
+
+  if (button->popover)
+    gtk_accessible_update_relation (GTK_ACCESSIBLE (button),
+                                    GTK_ACCESSIBLE_RELATION_CONTROLS, g_list_append (NULL, button->popover),
+                                    -1);
+  else
+    gtk_accessible_reset_relation (GTK_ACCESSIBLE (button),
+                                   GTK_ACCESSIBLE_RELATION_CONTROLS);
+}
+
 static void
 gtk_model_button_set_menu_name (GtkModelButton *button,
                                 const char     *menu_name)
@@ -637,6 +657,8 @@ gtk_model_button_set_menu_name (GtkModelButton *button,
   update_node_name (button);
   gtk_model_button_update_state (button);
 
+  update_accessible_properties (button);
+
   gtk_widget_queue_resize (GTK_WIDGET (button));
   g_object_notify_by_pspec (G_OBJECT (button), properties[PROP_MENU_NAME]);
 }
@@ -704,6 +726,8 @@ gtk_model_button_set_popover (GtkModelButton *button,
       gtk_popover_set_position (GTK_POPOVER (button->popover), GTK_POS_RIGHT);
     }
 
+  update_accessible_properties (button);
+
   update_node_name (button);
   gtk_model_button_update_state (button);
 
@@ -1186,7 +1210,8 @@ gtk_model_button_class_init (GtkModelButtonClass *class)
   widget_class->activate_signal = signals[SIGNAL_CLICKED];
 
   gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
-  gtk_widget_class_set_css_name (GTK_WIDGET_CLASS (class), I_("modelbutton"));
+  gtk_widget_class_set_css_name (widget_class, I_("modelbutton"));
+  gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_MENU_ITEM);
 }
 
 static void